<?php
$user = "user";
$pass = "pass";
$dbname = "test";
try {
    error_reporting(E_ALL | E_STRICT);
    $db = new PDO('mysql:host=127.0.0.1;dbname=' . $dbname, $user, $pass);
    $db -> setAttribute(PDO::FETCH_NAMED, PDO::ERRMODE_EXCEPTION);
    $stm = $db -> query("SELECT * FROM tabella WHERE 1=0");
    //echo $stm->columnCount();
    foreach (range(0, $stm->columnCount() - 1) as $idx) {
        $meta = $stm->getColumnMeta($idx);
        echo "$idx";
        var_dump($meta);
    }
    
} catch (PDOException $e) {
    print "Error!: " . $e -> getMessage() . "<br/>";
    die();
}
?>